﻿using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace Rework.SocialMetadata {
    public class Migrations : DataMigrationImpl {
        public int Create() {

            // Did not mean to create as a Versioned Record - caused problems

            //SchemaBuilder.CreateTable("SocialMetadataPartRecord",
            //    table => table
            //        .ContentPartVersionRecord()
            //        .Column<string>("Pattern", c => c.Unlimited()));

            //ContentDefinitionManager.AlterPartDefinition("SocialMetadataPart", part => part.Attachable());

            return 2;
        }

        public int UpdateFrom1() {
            SchemaBuilder.DropTable("SocialMetadataPartRecord");
            return 2;
        }

        public int UpdateFrom2() {            
            SchemaBuilder.CreateTable("SocialMetadataPartRecord",
                table => table
                    .ContentPartRecord()
                    .Column<string>("Pattern", c => c.Unlimited())
                    .Column<bool>("UsePattern"));

            ContentDefinitionManager.AlterPartDefinition("SocialMetadataPart", part => part.Attachable());
            return 3;
        }

    }
}